package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.Article;
import com.hl.sfzy.mapper.ArticleMapper;
import com.hl.sfzy.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;
    @Override
    public int add(Article article) {
        return articleMapper.insert(article);
    }

    @Override
    public int remove(Long id) {
        return articleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int edit(Article article) {
        return articleMapper.updateByPrimaryKeySelective(article);
    }

    @Override
    public Article findById(Long id) {
        return articleMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Article> findAll(int pageNum, int pageSize, Article article) {
        PageHelper.startPage(pageNum,pageSize);
        List<Article> articles = articleMapper.selectAll(article);
        PageInfo<Article> pageInfo = new PageInfo<>(articles);
        return pageInfo;
    }

    @Override
    public int deleteBatch(List<Long> ids) {
        return articleMapper.deleteBatch(ids);
    }

    @Override
    public List<Article> findArticleConsultants(Long id) {
        return articleMapper.selectArticleConsultants(id);
    }
}
